from django.shortcuts import render
from django.conf import settings

from user.models import *
from user.serializers import *

from rest_framework.views import APIView
from rest_framework.viewsets import ViewSet
from rest_framework.response import Response
from rest_framework import status
from rest_framework.response import Response

import alipay
import time
from datetime import datetime

from django.http import HttpResponse
from django.db.models import Q
from django.db.models import F

from utils.redis_middleware import redis_conn
import string
import random
import json
import datetime
import time


# 分类
class LassifysView(APIView):

    # 获取全部分类
    def get(self, request):
        try:
            type = TypeModel.objects.filter().all()
            type_ser = TypeSerializers(type, many=True).data
            return Response({"cdoe": status.HTTP_200_OK, "msg":"获取成功", "data": type_ser})
        except Exception as e:
            print("错误e")
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR, "msg":"服务器错误"})


# 标签
class LableView(APIView):

    # 获取全部标签
    def get(self, request):
        try:
            lable = LabelModel.objects.filter().all()
            lable_ser = LabelSerializers(lable, many=True).data
            return Response({"cdoe": status.HTTP_200_OK, "msg":"获取成功", "data": lable_ser})
        except Exception as e:
            print("错误e")
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR, "msg":"服务器错误"})


# 学习内容
class ContentsView(APIView):

    # 获取所有学习内容
    def get(self,request):
        try:
            content = LearningContentModel.objects.filter().all()
            content_ser = LearningContentSerializers(content,many=True).data
            return Response({"cdoe": status.HTTP_200_OK,"msg": "获取成功","data": content_ser})
        except Exception as e:
            print("错误",e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR,"msg": "服务器错误"})

    # 添加学习内容
    def post(self,request):
        try:
            learning_content_name = request.data.get("learning_content_name")
            user = request.data.get("user")
            type = request.data.get("type")
            label = request.data.get("label")
            content = request.data.get("content")
            is_status = request.data.get("is_status")
            print("接收", request.data)

            user_id = UserModel.objects.filter(user_name=user, is_delete=0).first()
            if user_id == None:
                return Response({"code": status.HTTP_400_BAD_REQUEST, "msg":'该用户不存在或以离职'})
            user_id = UserSerializers(user_id).data.get("id")

            type_id = TypeModel.objects.filter(type_name=type).first()
            if type_id == None:
                return Response({"code": status.HTTP_400_BAD_REQUEST, "msg":'该类别不存在'})
            type_id = TypeSerializers(type_id).data.get("id")

            label_id = LabelModel.objects.filter(label_name=label).first()
            if label_id == None:
                return Response({"code": status.HTTP_400_BAD_REQUEST, "msg":'该标签不存在'})
            label_id = LabelSerializers(label_id).data.get("id")

            print("id", user_id, type_id, label_id)

            data = {
                "learning_content_name": learning_content_name,
                "user": user,
                "type": type,
                "label": label,
                "content": content,
                "is_status": is_status
            }
            ser = LearningContentSerializers(data=data)
            if ser.is_valid():
                return Response({"code": status.HTTP_400_BAD_REQUEST, "msg":"错误", "data":ser.errors})

            LearningContentModel.objects.create(learning_content_name=learning_content_name, user_id=user_id, type_id=type_id, label=label, content=content, is_status=is_status)
            return Response({"code": status.HTTP_200_OK, "msg":"成功"})

            # LearningContentModel.objects.get(learning_content_name=)
        except Exception as e:
            print(e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR, "msg":"错误"})


class ContentsViewTow(ViewSet):

    # 获取单个学习内容
    def ont_content(self, request, id):
        try:
            content = LearningContentModel.objects.filter(id=id).all()
            content_ser = LearningContentSerializers(content,many=True).data
            return Response({"cdoe": status.HTTP_200_OK,"msg": "获取成功","data": content_ser})
        except Exception as e:
            print("错误",e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR,"msg": "服务器错误"})

    # 删除单个学习内容
    def del_content(self, request, id):
        try:
            LearningContentModel.objects.filter(id=id).update(is_delete=1)
            return Response({"cdoe": status.HTTP_200_OK,"msg": "删除成功"})
        except Exception as e:
            print("错误",e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR,"msg": "服务器错误"})

    # 修改学习内容
    def upd_content(self, request, id):
        try:
            learning_content_name = request.data.get("learning_content_name")
            user = request.data.get("user")
            type = request.data.get("type")
            label = request.data.get("label")
            content = request.data.get("content")
            is_status = request.data.get("is_status")
            print("接收", request.data)

            user_id = UserModel.objects.filter(user_name=user, is_delete=0).first()
            if user_id == None:
                return Response({"code": status.HTTP_400_BAD_REQUEST, "msg":'该用户不存在或以离职'})
            user_id = UserSerializers(user_id).data.get("id")

            type_id = TypeModel.objects.filter(type_name=type).first()
            if type_id == None:
                return Response({"code": status.HTTP_400_BAD_REQUEST, "msg":'该类别不存在'})
            type_id = TypeSerializers(type_id).data.get("id")

            label_id = LabelModel.objects.filter(label_name=label).first()
            if label_id == None:
                return Response({"code": status.HTTP_400_BAD_REQUEST, "msg":'该标签不存在'})
            label_id = LabelSerializers(label_id).data.get("id")

            print("id", user_id, type_id, label_id)

            data = {
                "learning_content_name": learning_content_name,
                "user": user,
                "type": type,
                "label": label,
                "content": content,
                "is_status": is_status
            }
            ser = LearningContentSerializers(data=data)
            if ser.is_valid():
                return Response({"code": status.HTTP_400_BAD_REQUEST, "msg":"错误", "data":ser.errors})

            LearningContentModel.objects.filter(id=id).update(learning_content_name=learning_content_name, user_id=user_id, type_id=type_id, label=label, content=content, is_status=is_status)
            return Response({"code": status.HTTP_200_OK, "msg":"成功"})

            # LearningContentModel.objects.get(learning_content_name=)
        except Exception as e:
            print(e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR, "msg":"错误"})


# 学习资料LearningResourcesModel
class MaterialsView(APIView):

    # 获取所有学习资料
    def get(self, request):
        try:
            materials = LearningResourcesModel.objects.filter().all()
            materials_ser = LearningResourcesSerializers(materials,many=True).data
            return Response({"cdoe": status.HTTP_200_OK,"msg": "获取成功","data": materials_ser})
        except Exception as e:
            print("错误",e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR,"msg": "服务器错误"})

    # 添加学习资料
    def post(self, request):
        try:
            learning_Resources_name = request.data.get("learning_Resources_name")
            user = request.data.get("user")
            price = request.data.get("price")
            describe = request.data.get("describe")

            user_id = UserModel.objects.filter(user_name=user, is_delete=0).first()
            if user_id == None:
                return Response({"code": status.HTTP_400_BAD_REQUEST, "msg":'该用户不存在或以离职'})
            user_id = UserSerializers(user_id).data.get("id")

            data = {
                "learning_Resources_name": learning_Resources_name,
                "user": user,
                "price": price,
                "describe": describe,
            }
            ser = LearningResourcesSerializers(data=data)
            if ser.is_valid():
                return Response({"code": status.HTTP_400_BAD_REQUEST, "msg":"错误", "data":ser.errors})

            LearningResourcesModel.objects.create(learning_Resources_name=learning_Resources_name, user_id=user_id, price=price,describe=describe)
            return Response({"code": status.HTTP_200_OK, "msg":"成功"})
        except Exception as e:
            print(e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR, "msg":"错误"})


# 学习资料
class MaterialsViewTow(ViewSet):

    # 获取单个学习资料
    def one_mater(self, request, id):
        try:
            materials = LearningResourcesModel.objects.filter(id=id).all()
            return Response({"cdoe": status.HTTP_200_OK,"msg": "获取成功"})
        except Exception as e:
            print("错误",e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR,"msg": "服务器错误"})

    # 删除学习资料
    def del_mater(self, request, id):
        try:
            LearningResourcesModel.objects.filter(id=id).update(is_delete=1)
            return Response({"cdoe": status.HTTP_200_OK,"msg": "删除成功"})
        except Exception as e:
            print("错误",e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR,"msg": "服务器错误"})

    # 修改学习资料
    def upd_mater(self, request, id):
        try:
            learning_Resources_name = request.data.get("learning_Resources_name")
            user = request.data.get("user")
            price = request.data.get("price")
            describe = request.data.get("describe")

            user_id = UserModel.objects.filter(user_name=user, is_delete=0).first()
            if user_id == None:
                return Response({"code": status.HTTP_400_BAD_REQUEST, "msg":'该用户不存在或以离职'})
            user_id = UserSerializers(user_id).data.get("id")

            data = {
                "learning_Resources_name": learning_Resources_name,
                "user": user,
                "price": price,
                "describe": describe,
            }
            ser = LearningResourcesSerializers(data=data)
            if ser.is_valid():
                return Response({"code": status.HTTP_400_BAD_REQUEST, "msg":"错误", "data":ser.errors})

            LearningResourcesModel.objects.filter(id=id).update(learning_Resources_name=learning_Resources_name, user_id=user_id, price=price,describe=describe)
            return Response({"code": status.HTTP_200_OK, "msg":"成功"})
        except Exception as e:
            print(e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR, "msg":"错误"})


# 学习任务
class LearningsView(APIView):

    # 获取所有学习任务
    def get(self,request):
        try:
            task = LearningTaskModel.objects.filter().all()
            task_ser = LearningTaskSerializers(task,many=True).data
            return Response({"cdoe": status.HTTP_200_OK,"msg": "获取成功","data": task_ser})
        except Exception as e:
            print("错误",e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR,"msg": "服务器错误"})

    # 添加学习任务
    def post(self,request):
        try:
            learning_task_name = request.data.get("learning_task_name")
            the_class = request.data.get("the_class")
            print(request.data)

            class_id = TheClassModel.objects.filter(the_class_name=the_class).first()
            if class_id == None:
                return Response({"code": status.HTTP_400_BAD_REQUEST, "msg":"该班级不存在"})
            class_id = TheClassSerializers(class_id).data.get("id")

            data = {
                "learning_task_name": learning_task_name,
                "the_class": the_class,
            }

            ser = TheClassSerializers(data=data)
            if ser.is_valid():
                return Response({"code": status.HTTP_400_BAD_REQUEST,"msg": "错误","data": ser.errors})

            LearningTaskModel.objects.create(learning_task_name=learning_task_name, the_class_id=class_id)
            return Response({"code": status.HTTP_200_OK,"msg": "成功"})
        except Exception as e:
            print(e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR,"msg": "错误"})

        # 问候语__gt 大于


# 学习任务2
class LearningViewTow(ViewSet):

    # 查询单个
    def one_learning(self, request, id):
        try:
            task = LearningTaskModel.objects.filter(id=id).all()
            task_ser = LearningTaskSerializers(task,many=True).data
            return Response({"cdoe": status.HTTP_200_OK,"msg": "获取成功","data": task_ser})
        except Exception as e:
            print("错误",e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR,"msg": "服务器错误"})

    # 删除一个
    def del_learning(self, request, id):
        try:
            task = LearningTaskModel.objects.filter(id=id).update(is_delete=1)
            return Response({"cdoe": status.HTTP_200_OK,"msg": "删除成功"})
        except Exception as e:
            print("错误",e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR,"msg": "服务器错误"})

    # 修改一个
    def upd_learning(self, request, id):
        try:
            learning_task_name = request.data.get("learning_task_name")
            the_class = request.data.get("the_class")
            print(request.data)

            class_id = TheClassModel.objects.filter(the_class_name=the_class).first()
            if class_id != None:
                return Response({"code": status.HTTP_400_BAD_REQUEST, "msg":"该班级已存在"})
            class_id = TheClassSerializers(class_id).data.get("id")

            data = {
                "learning_task_name": learning_task_name,
                "the_class": the_class,
            }

            ser = TheClassSerializers(data=data)
            if ser.is_valid():
                return Response({"code": status.HTTP_400_BAD_REQUEST,"msg": "错误","data": ser.errors})

            LearningTaskModel.objects.filter(id=id).update(learning_task_name=learning_task_name, the_class_id=class_id)
            return Response({"code": status.HTTP_200_OK,"msg": "成功"})
        except Exception as e:
            print(e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR,"msg": "错误"})


# 学习内容到资料
class NZView(APIView):
    def post(self, request):
        try:
            content = request.data.get("content")
            resource = request.data.get("resource")

            data = {
                "content": content,
                "resource": resource
            }

            ser = ResourcesContentSerializers(data=data)

            if ser.is_valid():
                return Response({"code": status.HTTP_400_BAD_REQUEST,"msg": "错误","data": ser.errors})

            ResourcesContentModel.objects.create(content_id=content,resource_id=resource)

            return Response({"code": status.HTTP_200_OK,"msg": "成功"})
        except Exception as e:
            print(e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR, "smg":"错误"})


class NZViewTow(APIView):

    def get(self, request, id):
        try:
            rcm = ResourcesContentModel.objects.filter(resource=id, is_delete=0).all()
            rcm_ser = ResourcesContentSerializers(rcm, many=True).data
            return Response({"code": status.HTTP_200_OK, "msg":"成功", "data":rcm_ser})
        except Exception as e:
            print(e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR, "smg":"错误"})

    def delete(self, request):
        try:
            ResourcesContentModel.objects.filter(resource=id,is_delete=0).update(is_delete=0)
            return Response({"code": status.HTTP_200_OK,"msg": "成功"})
        except Exception as e:
            print(e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR,"smg": "错误"})


# 学习内容到任务
class NRView(APIView):
    def post(self, request):
        try:
            task = request.data.get("task")
            content = request.data.get("content")

            data = {
                "task": task,
                "content": content
            }

            ser = ResourcesTaskSerializers(data=data)

            if ser.is_valid():
                return Response({"code": status.HTTP_400_BAD_REQUEST,"msg": "错误","data": ser.errors})

            ResourcesTaskModel.objects.create(task_id=task,content_id=content)

            return Response({"code": status.HTTP_200_OK,"msg": "成功"})
        except Exception as e:
            print(e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR, "smg":"错误"})


class NRViewTow(APIView):
    def get(self, request, id):
        try:
            rcm = ResourcesTaskModel.objects.filter(task=id,is_delete=0).all()
            rcm_ser = ResourcesTaskSerializers(rcm,many=True).data
            return Response({"code": status.HTTP_200_OK,"msg": "成功","data": rcm_ser})
        except Exception as e:
            print(e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR,"smg": "错误"})

    def delete(self, request):
        try:
            ResourcesTaskModel.objects.filter(task=id,is_delete=0).update(is_delete=1)
            return Response({"code": status.HTTP_200_OK,"msg": "成功"})
        except Exception as e:
            print(e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR,"smg": "错误"})

# __lt 小于
# __gte 大于等于
# __lte 小于等于
class GreetingsView(APIView):

    # 问候语查询
    def get(self, request):
        t = time.localtime()
        current_time = time.strftime("%H:%M:%S",t)
        print(current_time)
        ls = []
        list = Greetings.objects.filter(Q(start_time__lte=str(current_time)) & Q(end_time__gte=str(current_time))).all()
        print(list.query)
        for i in list:
            ls.append(i.id)
        id = random.choice(ls)
        greet = Greetings.objects.get(id=id)
        return Response({"code": status.HTTP_200_OK,"msg": "成功",'data': greet.content})


# 点赞
class LikeView(APIView):
    def post(self, request):
        try:
            user = request.data.get("user")
            count = request.data.get("count")
            print("接受的数据",request.data)

            user_id = UserModel.objects.get(user_name=user).id
            count_id = LearningContentModel.objects.get(learning_content_name=count).id

            like = LikeModel.objects.filter(user=user_id,content=count_id).first()
            like_ser = LikeSerializers(like).data
            print(like)
            print(like_ser)
            if like != None:
                if like_ser.get("is_like") == 0:
                    LikeModel.objects.filter(user_id=user_id,content_id=count_id).update(is_like=1)
                    is_like = True
                    return Response({"code": status.HTTP_200_OK,"msg": "点赞成功","data": is_like})
                else:
                    LikeModel.objects.filter(user_id=user_id,content_id=count_id).update(is_like=0)
                    is_like = False
                    return Response({"code": status.HTTP_200_OK,"msg": "取消点赞成功","data": is_like})
            else:
                LikeModel.objects.create(user_id=user_id,content_id=count_id,is_like=1)
                is_like = True
                return Response({"code": status.HTTP_200_OK,"msg": "点赞成功","data": is_like})
        except Exception as e:
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR, "msg":'数据错误或服务器错误'})


# 收藏
class CollectView(APIView):
    def post(self, request):
        try:
            user = request.data.get("user")
            count = request.data.get("count")
            print("接受的数据",request.data)

            user_id = UserModel.objects.get(user_name=user).id
            count_id = LearningContentModel.objects.get(learning_content_name=count).id

            collect = CollectModel.objects.filter(user=user_id,content=count_id).first()
            collect_ser = CollectSerializers(collect).data
            print(collect)
            print(collect_ser)
            if collect != None:
                if collect_ser.get("is_collect") == 0:
                    CollectModel.objects.filter(user_id=user_id,content_id=count_id).update(is_collect=1)
                    is_collect = True
                    return Response({"code": status.HTTP_200_OK,"msg": "收藏成功","data": is_collect})
                else:
                    CollectModel.objects.filter(user_id=user_id,content_id=count_id).update(is_collect=0)
                    is_collect = False
                    return Response({"code": status.HTTP_200_OK,"msg": "取消收藏成功","data": is_collect})
            else:
                CollectModel.objects.create(user_id=user_id,content_id=count_id,is_collect=1)
                is_collect = True
                return Response({"code": status.HTTP_200_OK,"msg": "收藏成功","data": is_collect})
        except Exception as e:
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR, "msg":'数据错误或服务器错误'})


app_private_key_string = open(settings.APP_PRIVATE_KEY_PATH,'r').read()

# 读取支付宝公钥
alipay_public_key_string = open(settings.ALIPAY_PUBLIC_KEY_PATH,'r').read()
import random


# 支付宝沙箱支付的配置
class MyAlipay(ViewSet):
    def __init__(self, *args, **kwargs):
        super(MyAlipay, self).__init__(*args, **kwargs)
        # 自己定义
        self.alipay = alipay.AliPay(
            appid="2021000119635027",
            app_private_key_string = app_private_key_string,
            alipay_public_key_string = alipay_public_key_string,
            app_notify_url=None,
            sign_type='RSA2',
            debug=True # 所有的请求 定向到沙箱服务
        )

    def get_pay_url(self, order_id, total_amount):
        print("接收到的参数", order_id, total_amount)
        order_string = self.alipay.api_alipay_trade_page_pay(
            subject="商家收款",
            out_trade_no=order_id,
            total_amount=total_amount,
            return_url="http://localhost:8080/store",
            notify_url="http://localhost:8080/store"
        )

        # 支付地址
        return "https://openapi.alipaydev.com/gateway.do?"+order_string


# # 订单的创建
# class OrderView(MyAlipay):
#     # 支付订单
#     def post_order(self, request):
#         # 接收数据
#         goods_list = request.data.get("goods_list")
#         user_id = request.data.get("user_id")
#         addr_id = request.data.get("addr_id")
#         print("goods_list", goods_list)
#         print("user_id", user_id)
#         print("addr_id", addr_id)
#
#         order_id = datetime.now().strftime("%Y%m%d%H%M%S")+"%s"%user_id
#         try:
#             # 查找并判断数据是否存在
#             tomoneys = 0
#             numbers = 0
#             addrs = AddressModel.objects.filter()
#             if not addrs:
#                 return Response({"code": 204, "msg":"地址不存在"})
#             print("运行到了for循环")
#             for good in goods_list:
#                 tomoneys += float(good["price"]) * int(good["num"])
#                 numbers += int(good["num"])
#                 print("运行到了添加order")
#             OrderModel.objects.create(order_id=int(order_id), user_id=user_id, shops_id=1,
#                                               total_amount=tomoneys, sum=numbers, pay_method=1, address_id=addr_id)
#             # 循环并遍历出想对的总数和总价格
#             for good in goods_list:
#                 tomoneys += float(good["price"]) * int(good["num"])
#                 numbers += int(good["num"])
#                 order = OrderModel.objects.get(order_id=order_id)
#                 print("运行到了添加order_goods")
#                 order_goods = OrderGoodsModel.objects.create(order_id=int(order.id),goods_id=good["id"], sum=good["num"], sum_price=numbers)
#
#                 print("运行到了删除购物车内容",)
#                 # UserShoppingModel.objects.get(id=good["user_shopping_id"]).delete()
#
#                 print("for运行成功")
#             print("订单创建成功",order_id, tomoneys, type(order_id))
#             total_amount = float(tomoneys)
#             pay_url = self.get_pay_url(order_id, total_amount)
#             print("路由pay_url>>>>>>>>>>>>>>>>>>>>", pay_url)
#             return Response({"code": 200, "msg": "创建订单成功", 'url': pay_url, "data":order_id})
#         except Exception as e:
#             print("失败》》》》》》", e)
#             return Response({"code": 500, "msg": "创建订单失败"})
#     # 支付判定
#     def post_check(self, request):
#         try:
#             out_trade_no = request.data.get("out_trade_no")
#             trade_on = request.data.get("trade_on")
#             print("接收到的参数", trade_on, out_trade_no)
#             order = OrderModel.objects.filter(order_id=out_trade_no)
#             if not order:
#                 return Response({"code": 204,"msg": "订单不存在"})
#
#             check = self.alipay.api_alipay_trade_query(out_trade_no)
#             if not check.get("trade_status") == "TRADE_SUCCESS":
#                 return Response({"code": 204,"msg": '支付失败'})
#             order.update(pay_state=4)
#             return Response({"code": 200,"msg": "支付成功"})
#         except Exception as e:
#             print("错误报错", e)
#             return Response({"code":500,"msg":"服务器错误"})
#
#
# # 获取订单
# class OrdersView(ViewSet):
#     # 获取对应的所有订单
#     def all_order(self, request, pay_state):
#         try:
#             user_id = request.data.get("user_id")
#             # print("接收到的参数", user_id)
#             print("user", user_id, pay_state)
#             order_list = OrderModel.objects.filter(user=user_id, pay_state=pay_state)
#             order_list_ser = OrderSer(order_list,many=True)
#             return Response({"code": 200,"msg": "获取成功","data": order_list_ser.data})
#         except Exception as e:
#             print("获取订单失败", e)
#             return Response({"code":500,"msg":"获取失败"})
#
#     # 获取订单详情
#     def all_order_goods(self, request, order_id):
#         try:
#             # order_id = request.data.get("order_id")
#             print("接收到数据", order_id)
#             order_goods_list = OrderGoodsModel.objects.filter(order_id=order_id)
#             order_goods_list = OrderGoodsSer(order_goods_list, many=True)
#             return Response({"code": 200,"msg": "获取成功","data": order_goods_list.data})
#         except Exception as e:
#             print("获取订单对应商品失败", e)
#             return Response({"code":500,"msg":"获取失败"})
#
#     def get_all_order(self, request, pk):
#         try:
#             # print("接收到的参数", user_id)
#             print("user", pk)
#             order_list = OrderModel.objects.filter(user=pk, pay_state=1)
#             order_list_ser = OrderSer(order_list,many=True)
#             return Response({"code": 200,"msg": "获取成功","data": order_list_ser.data})
#         except Exception as e:
#             print("获取订单失败", e)
#             return Response({"code":500,"msg":"获取失败"})
#
#     def all_good(self, request, pay_state):
#         try:
#             shops_id = request.data.get("shops_id")
#             print("shops", shops_id, pay_state)
#             order_list = OrderModel.objects.filter(shops=shops_id, pay_state=pay_state)
#             order_list_ser = OrderSer(order_list,many=True)
#             return Response({"code": 200,"msg": "获取成功","data": order_list_ser.data})
#         except Exception as e:
#             print("获取订单失败", e)
#             return Response({"code":500,"msg":"获取失败"})




# 支付宝网关地址
# https://openapi.alipaydev.com/gateway.do
# jjmgrc9892@sandbox.com
# 111111






















































